﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;

namespace RN.ERP.Web.Person
{
    public partial class PersonEmpCertPrint : BasePage
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetParams();
                BindCertInfo();
            }
        }
        public override bool IsCheckPermission
        {
            get { return false; }
        }
        /// <summary>
        /// 取得参数
        /// </summary>
        private void GetParams()
        {
            ViewState["empGuid"] = "";
            ViewState["typeFlag"] = "";
            ViewState["certCode"] = "";
            ViewState["certCodeNew"] = "";
            ViewState["certCodeOld"] = "";
            ViewState["certNameOld"] = "";
            ViewState["beginDate"] = "";
            if (!string.IsNullOrEmpty(Request.QueryString["empGuid"]))
            {
                ViewState["empGuid"] = Request.QueryString["empGuid"].Trim();
            }
            //证书typeflag
            if (!string.IsNullOrEmpty(Request.QueryString["typeFlag"]))
            {
                ViewState["typeFlag"] = Request.QueryString["typeFlag"].Trim();
            }
            //证书编号
            if (!string.IsNullOrEmpty(Request.QueryString["certCode"]))
            {
                ViewState["certCode"] = Request.QueryString["certCode"].Trim();
            }
            //新证书编号
            if (!string.IsNullOrEmpty(Request.QueryString["certCodeNew"]))
            {
                ViewState["certCodeNew"] = Request.QueryString["certCodeNew"].Trim();
            }
            //申报证书编号
            if (!string.IsNullOrEmpty(Request.QueryString["certCodeOld"]))
            {
                ViewState["certCodeOld"] = Request.QueryString["certCodeOld"].Trim();
            }
            //申报证书名称
            if (!string.IsNullOrEmpty(Request.QueryString["certNameOld"]))
            {
                ViewState["certNameOld"] = Request.QueryString["certNameOld"].Trim();
            }
          
            if (!string.IsNullOrEmpty(Request.QueryString["beginDate"]))
            {
                ViewState["beginDate"] = Request.QueryString["beginDate"].Trim();
            }
        }
        /// <summary>
        /// 取得数据源绑定数据
        /// </summary>
        private void BindCertInfo()
        {
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                var qualitie = JsonConvert.DeserializeObject<ModelService.OperationResult>(client.GetEmpCertInfoPrint(ViewState["empGuid"].ToString(),ViewState["typeFlag"].ToString(),ViewState["certCode"].ToString(), UserInfo.CurrentArea));
                if (qualitie.Result && qualitie.ReturnValue!=null)
                {
                    SetCertValues(JsonConvert.DeserializeObject<ModelService.tb_Emp_Manager>(qualitie.ReturnValue.ToString()));
                }
            }
        }
        /// <summary>
        /// 取得字典数据
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        protected Dictionary<string, string> GetGetDictionary(string type, string condition)
        {
            using (BasicService.BasicServiceClient client = new BasicService.BasicServiceClient())
            {
                return JsonConvert.DeserializeObject<Dictionary<string, string>>(client.GetDictionary(type, condition, UserInfo.CurrentArea));
            }
        }
        /// <summary>
        /// 数据赋值
        /// </summary>
        /// <param name="manager"></param>
        private void SetCertValues(ModelService.tb_Emp_Manager manager)
        {
            lbld_codet.Text = ViewState["certCodeNew"].ToString();
           // lbld_zjt.Text = manager.CertificateLevel;
            lbld_cydwZ.Text = manager.corpName;
            lbld_xmZ.Text = manager.Name;
            lbld_xbZ.Text=manager.Sex==1 ? "男":"女";
            lbld_sfzhZ.Text=manager.IDCard;
            Dictionary<string, string> dict=GetGetDictionary("empdegree", "");
            if (dict.ContainsKey(manager.Education))
            {
                lbld_xlZ.Text = dict[manager.Education];
            }
            Dictionary<string, string> dict1=GetGetDictionary("empmajor", "");
            if (dict.ContainsKey(manager.DoMajor))
            {
                lbld_sxzyZ.Text = dict1[manager.DoMajor];
            }
            lbld_zcZ.Text = manager.Post_Title;
            lbld_yxqzZ.Text = ViewState["certNameOld"].ToString();// manager.CertificateName;
            lbld_zsbhZ.Text = ViewState["certCodeOld"].ToString();// manager.CertificateCode;
           // lblfzjgt.Text = ViewState["org"].ToString();
            lbld_fzrqZ.Text = ViewState["beginDate"].ToString();
            if (!string.IsNullOrEmpty(manager.CertificateSpecialty))
            {
                string[] Specialty = manager.CertificateSpecialty.Split(',');

                lbld_zy1Z.Text = Specialty[0];
                if (Specialty.Length > 1)
                {
                    lbld_zy2Z.Text = Specialty[1];
                }
            }
        }
    }
}